
package com.gamatechno.solodestinationnew.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RatingBar;
import android.widget.TextView;

import com.gamatechno.solodestinationnew.R;
import com.gamatechno.solodestinationnew.entity.E_Location;

public class AdapterSearch extends BaseAdapter {

    private List<E_Location> listSearch;
    private LayoutInflater inflater;

    public AdapterSearch(Context context, List<E_Location> listSearch) {
        this.listSearch = listSearch;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return listSearch.size();
    }

    @Override
    public Object getItem(int arg0) {
        return listSearch.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        return 0;
    }

    static class Holder {
        TextView title, distance;
        RatingBar rate;
    }

    @Override
    public View getView(int arg0, View view, ViewGroup arg2) {
        Holder holder;

        if (view == null) {
            view = inflater.inflate(R.layout.item_search, null);

            holder = new Holder();
            holder.title = (TextView) view.findViewById(R.id.title_result_search);
            holder.distance = (TextView) view.findViewById(R.id.distance_result_search);
            holder.rate = (RatingBar) view.findViewById(R.id.rating_result_search);

            view.setTag(holder);
        } else {
            holder = (Holder) view.getTag();
        }

        holder.title.setText(listSearch.get(arg0).getName());
        holder.rate.setRating(listSearch.get(arg0).getRate());
        holder.distance
                .setText("" + String.format("%.2f", listSearch.get(arg0).getJarak()) + " km");

        return view;
    }

}
